#include<bits/extc++.h>
#define eps 1e-7
#define endl '\n'
#define ls (p<<1)
#define rs (p<<1|1)
#define lb(x) (x&-x)
#define pie acos(-1)
#define int long long
#define mid ((l+r)/2)
#define mod 1000000007
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)
#define ull unsigned long long
#define inf 4557430888798830399
#define mgp gp_hash_table<int,int>
#define ms0(a) memset(a,0,sizeof(a))
#define myCase int T;for(cin>>T;T--;)
#define mst(a,b) memset(a,b,sizeof(a))
#define IOS std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pri __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag>
#define rbt tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define tri trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
struct node{
    int a,b;
    string na;
}nd[100010];
int n;
bool cmp(node x,node y){
    if(x.a==y.a) return x.na<y.na;
    return x.a>y.a;
}
void mySolve(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>nd[i].na>>nd[i].a;
    sort(nd+1,nd+1+n,cmp);
    for(int i=1,cnt=1;i<=n;i++){
        if(nd[i].a!=nd[i-1].a) cnt=i;
        cout<<cnt<<" "<<nd[i].na<<endl;
    }
}
signed main(){IOS
 //myCase
    mySolve();
return 0;}
/*  stuff you should look for
 *  int overflow, array bounds
 *  special cases (n=1?)
 *  do smth instead of nothing and stay organized
 *  WRITE STUFF DOWN
 *  DON'T GET STUCK ON ONE APPROACH
 * -- Benq
 * */